<!--
 * @Description: 
 * @Date: 2024-07-08 09:20:03
 * @LastEditTime: 2024-07-31 10:55:03
-->
<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">
    <el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="办结结果" prop="resultStatus">
            <el-radio-group v-model="formData.resultStatus" size="large">
              <el-radio-button label="1" value="1">已处理</el-radio-button>
              <el-radio-button label="2" value="2">延后处理</el-radio-button>
              <el-radio-button label="3" value="3">不予处理</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="办结说明" prop="result">
            <el-input v-model="formData.result" type="textarea" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { FormRules, resultProps } from 'element-plus'
import * as ReportApi from '@/api/countryside/report'
const locationOptions = ['已处理', '延后处理', '不予处理']
const reportId = ref(null)
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('办结') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  resultStatus: '',
  result: ''
})
const emit = defineEmits(['success'])
const formRules = reactive<FormRules>({
  resultStatus: [{ required: true, message: '办结结果不能为空', trigger: 'change' }],
  result: [{ required: true, message: '办结说明不能为空', trigger: 'blur' }]
})
const formRef = ref()
/** 打开弹窗 */
const open = async (id) => {
  reportId.value = id
  dialogVisible.value = true
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
const submitForm = async () => {
  if (!formRef) return
  const valid = await formRef.value.validate()
  if (!valid) return
  // 提交请求
  formLoading.value = true
  await ReportApi.updateReport({
    id: reportId.value,
    resultStatus: formData.value.resultStatus,
    result: formData.value.result,
    status: 3
  })
  dialogVisible.value = false
  //发送操作成功的事件
  emit('success', true)
}
</script>
<style lang="scss" scoped></style>
